cmake_minimum_required(VERSION 3.13)
project(vvxfconf)

set(LIBXFCONF_VERSION_API 0)
set(LIBXFCONF_VERINFO 3:0:0)
set(XFCONF_SERVICE_NAME_PREFIX "org.vvxfce")
set(XFCONF_SERVICE_PATH_PREFIX "/org/vvxfce")
set(HELPER_PATH_PREFIX "lib")

add_definitions(-DBUILD_XFCONF_BACKEND_PERCHANNEL_XML=1)

add_definitions(-DXFCONF_SERVICE_NAME_PREFIX="${XFCONF_SERVICE_NAME_PREFIX}")
add_definitions(-DXFCONF_SERVICE_PATH_PREFIX="${XFCONF_SERVICE_PATH_PREFIX}")
add_definitions(-DHAVE_GNUC_VISIBILITY)

set(IS_ALONE_COMPILE TRUE)
if (NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
        set(IS_ALONE_COMPILE FALSE)
endif()

include(cmake/my_utils.cmake)
include(cmake/my_glib_utils.cmake)

set(IS_ALONE_COMPILE TRUE)
if (NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
        set(IS_ALONE_COMPILE FALSE)
endif()

find_package(PkgConfig)
if (${IS_ALONE_COMPILE})
pkg_check_modules(GLIB IMPORTED_TARGET glib-2.0)
pkg_check_modules(GIO IMPORTED_TARGET gio-2.0)
pkg_check_modules(GIO_UNIX IMPORTED_TARGET gio-unix-2.0)
pkg_check_modules(GMODULE IMPORTED_TARGET gmodule-2.0)
pkg_check_modules(GTHREAD IMPORTED_TARGET gthread-2.0)

# pkg_check_modules(GTK IMPORTED_TARGET gtk+-3.0)
# pkg_check_modules(XCOMPOSITE IMPORTED_TARGET xcomposite)
# pkg_check_modules(EPOXY IMPORTED_TARGET epoxy)
# pkg_check_modules(X11 IMPORTED_TARGET x11)
# pkg_check_modules(STARTUP_NOTIFICATION IMPORTED_TARGET libstartup-notification-1.0)
# pkg_check_modules(XFCE4_KBD_PRIVATE IMPORTED_TARGET libxfce4kbd-private-3)
# pkg_check_modules(XFCE4_UI IMPORTED_TARGET libxfce4ui-2)
pkg_check_modules(XFCE4_UTIL IMPORTED_TARGET libxfce4util-1.0)
# pkg_check_modules(XFCONF IMPORTED_TARGET libxfconf-0)
# pkg_check_modules(XPRESENT IMPORTED_TARGET xpresent)
# pkg_check_modules(XRENDER IMPORTED_TARGET xrender)
# pkg_check_modules(XINERAMA IMPORTED_TARGET xinerama)
# pkg_check_modules(XEXT IMPORTED_TARGET xext)
# pkg_check_modules(WNCK IMPORTED_TARGET libwnck-3.0)
# pkg_check_modules(POLKIT_GOBJECT IMPORTED_TARGET polkit-gobject-1)
# pkg_check_modules(SM IMPORTED_TARGET sm)
# pkg_check_modules(ICE IMPORTED_TARGET ice)
endif()

my_check_header_exists_and_define_macro("sys/types.h")
my_check_header_exists_and_define_macro("sys/wait.h")
my_check_header_exists_and_define_macro("sys/stat.h")
my_check_header_exists_and_define_macro("errno.h")
my_check_header_exists_and_define_macro("fcntl.h")
my_check_header_exists_and_define_macro("memory.h")
my_check_header_exists_and_define_macro("signal.h")
my_check_header_exists_and_define_macro("stdlib.h")
my_check_header_exists_and_define_macro("string.h")
my_check_header_exists_and_define_macro("unistd.h")
my_check_header_exists_and_define_macro("grp.h")
my_check_function_exists_and_define_macro(gethostname HAVE_GETHOSTNAME)

my_check_glib_type_align_and_define_macro(gboolean ALIGNOF_GBOOLEAN)
my_check_glib_type_align_and_define_macro(guint16 ALIGNOF_GUINT16)
my_check_glib_type_align_and_define_macro(gint16 ALIGNOF_GINT16)
my_check_glib_type_align_and_define_macro(guint32 ALIGNOF_GUINT32)
my_check_glib_type_align_and_define_macro(gint32 ALIGNOF_GINT32)
my_check_glib_type_align_and_define_macro(guint64 ALIGNOF_GUINT64)
my_check_glib_type_align_and_define_macro(gint64 ALIGNOF_GINT64)
my_check_glib_type_align_and_define_macro(gfloat ALIGNOF_GFLOAT)
my_check_glib_type_align_and_define_macro(gdouble ALIGNOF_GDOUBLE)
my_check_glib_type_align_and_define_macro(gpointer ALIGNOF_GPOINTER)
my_check_glib_type_align_and_define_macro(gchar ALIGNOF_GCHAR)
my_check_glib_type_align_and_define_macro(guchar ALIGNOF_GUCHAR)

add_library(marcos-interface INTERFACE)
target_compile_definitions(marcos-interface
        INTERFACE
        LIBXFCONF_COMPILATION
)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(common)
add_subdirectory(xfconf)
add_subdirectory(xfconfd)
add_subdirectory(xfconf-query)
# po \
# docs \
# tests

#
#if ENABLE_BASH_COMPLETION
#SUBDIRS += completions
#endif
#
#if XFCONF_ENABLE_GSETTINGS_BACKEND
#SUBDIRS += gsettings-backend
#endif
#
#.PHONY: ChangeLog
#
#ChangeLog: Makefile
#	(GIT_DIR=$(top_srcdir)/.git git log > .changelog.tmp \
#	&& mv .changelog.tmp ChangeLog; rm -f .changelog.tmp) \
#	|| (touch ChangeLog; echo 'Git directory not found: installing possibly empty changelog.' >&2)
#
#dist-hook: ChangeLog
#
#EXTRA_DIST = \
#	AUTHORS \
#	COPYING \
#	ChangeLog \
#	NEWS \
#	README.md \
#	m4/introspection.m4 \
#	m4/vapigen.m4
#
#DISTCHECK_CONFIGURE_FLAGS = \
#	--enable-gtk-doc \
#	--enable-introspection \
#	--disable-vala
